package com.kdweibo.demo.activities;

import java.util.List;

import kdweibo4j.Group;
import kdweibo4j.Paging;
import kdweibo4j.PagingByTime;
import kdweibo4j.Status;
import kdweibo4j.Weibo;
import kdweibo4j.WeiboException;
import kdweibo4j.http.AccessToken;


public class TestGroupTimeline {
	String token = "";
	String tokenSecret = "";
	String network = "kdweibo.cn";
	String groupID = "4f705c1d24acec7da09e2b03";
	
	public void getMyGroupList(){
		Weibo weibo = AuthConstant.getInstance().getWeibo();
		weibo.setNetwork(network);
		weibo.setOAuthConsumer(Weibo.CONSUMER_KEY, Weibo.CONSUMER_SECRET);
		weibo.setOAuthAccessToken(new AccessToken(token, tokenSecret));
		Paging page = new Paging();
		try {
			List<Group> groups = weibo.getJoinedGroup(page);
			for(int i=0;i<groups.size();i++){
				System.out.println("Group List ["+(i+1)+"]: "+groups.get(i).getId()+", "+groups.get(i).getName()+"\n");
			}
		} catch (WeiboException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	/**
	 * 返回指定id区间的关注微博列表
	 * 
	 */
	public void getFriendsTimeline(){
		
		Weibo weibo = AuthConstant.getInstance().getWeibo();
		weibo.setNetwork(network);
		weibo.setOAuthConsumer(Weibo.CONSUMER_KEY, Weibo.CONSUMER_SECRET);
		weibo.setOAuthAccessToken(new AccessToken(token, tokenSecret));
		Paging page = new Paging();
		try {
			List<Status> statuses = weibo.getGroupTimeline(page,groupID);
			for(int i=0;i<statuses.size();i++){
				System.out.println("["+(i+1)+"]: "+statuses.get(i).getUser().getName()+", "+statuses.get(i).getText());
			}
		} catch (WeiboException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	/**
	 * 返回截止到指定时间的小组微博列表
	 * 
	 */
	public void getFriendsTimelineByTime(){
		
		Weibo weibo = AuthConstant.getInstance().getWeibo();
		weibo.setNetwork(network);
		weibo.setOAuthConsumer(Weibo.CONSUMER_KEY, Weibo.CONSUMER_SECRET);
		weibo.setOAuthAccessToken(new AccessToken(token, tokenSecret));
		PagingByTime page = new PagingByTime();
		try {
			List<Status> statuses = weibo.getGroupTimelineOrderByTime(page,groupID);
			for(int i=0;i<statuses.size();i++){
				System.out.println("["+(i+1)+"]: "+statuses.get(i).getUser().getName()+", "+statuses.get(i).getText());
			}
		} catch (WeiboException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		TestGroupTimeline dgt = new TestGroupTimeline();
		dgt.getMyGroupList();
		System.out.println("==============================");
		dgt.getFriendsTimeline();
		System.out.println("==============================\n");
		dgt.getFriendsTimelineByTime();
	}

	
}
